package org.skipper.samples.redission.lists;

import org.redisson.api.RedissonClient;
import org.skipper.samples.redission.enums.RedisKeyEnum;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Description:
 *
 * @author shoujian
 * Date: 2021-08-20
 * Time: 下午3:58
 */
@Component
public class ListsSource {

    @Qualifier(value = "redis-cloud_0")
    @Resource
    private RedissonClient redissonClient;

    public void lindex() {
        String lindex_get = (String) redissonClient.getList(RedisKeyEnum.LISTS_TEST.getCode()).get(0);
        System.out.println("lindex_get = " + lindex_get);
    }

    public void llen() {
        int llen_size = redissonClient.getList(RedisKeyEnum.LISTS_TEST.getCode()).size();
        System.out.println("llen_size = " + llen_size);
    }

    public void lpop() {
        String lpop_poll = (String) redissonClient.getQueue(RedisKeyEnum.LISTS_TEST.getCode()).poll();
        System.out.println("lpop_poll = " + lpop_poll);
    }

    public void lpush() {
        redissonClient.getDeque(RedisKeyEnum.LISTS_TEST.getCode()).addFirst("lpush_test");
        redissonClient.getDeque(RedisKeyEnum.LISTS_TEST.getCode()).offerFirst("lpush_test");
    }

    public void lrange() {
        List<Object> lrange_readAll = redissonClient.getList(RedisKeyEnum.LISTS_TEST.getCode()).readAll();
        System.out.println("lrange_readAll = " + lrange_readAll.toString());
    }

    public void lrem() {
        redissonClient.getList(RedisKeyEnum.LISTS_TEST.getCode()).fastRemove(0);
        redissonClient.getList(RedisKeyEnum.LISTS_TEST.getCode()).remove(0);
        redissonClient.getDeque(RedisKeyEnum.LISTS_TEST.getCode()).removeFirstOccurrence("lrem_test");
        redissonClient.getDeque(RedisKeyEnum.LISTS_TEST.getCode()).removeLastOccurrence("lrem_test");
    }

    public void lset() {
        redissonClient.getList(RedisKeyEnum.LISTS_TEST.getCode()).fastSet(0, "lset_test");
    }

    public void ltrim() {
        redissonClient.getList(RedisKeyEnum.LISTS_TEST.getCode()).trim(0, 1);
    }


}
